﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI.ThemMoi
{
    public partial class KhachHangGUI : UserControl, GUI.UctrlGUI
    {
        BLL.ThemKhachHangBLL _ThemMoiKhachHangBLL;

        public KhachHangGUI()
        {
            InitializeComponent();
            _ThemMoiKhachHangBLL = new BLL.ThemKhachHangBLL();
        }

        public String getName()
        {
            return "THÊM MỚI KHÁCH HÀNG";
        }

        private void btn_ThemMoi_Click(object sender, EventArgs e)
        {
            if (txt_HoTen.Text == String.Empty)
            {
                MessageBox.Show("Họ Tên NULL");
                return;
            }

            if (txt_Email.Text == String.Empty)
            {
                MessageBox.Show("Email NULL");
                return;
            }

            DTO.KhachHangDTO dto = new DTO.KhachHangDTO();
            dto.HoTen = txt_HoTen.Text;
            dto.Email = txt_Email.Text;
            dto.DiaChi = txt_DiaChi.Text;
            dto.DienThoai = txt_DienThoai.Text;
            _ThemMoiKhachHangBLL.ThemMoi(dto);
            ResetGui();
        }

        private void btn_LamLai_Click(object sender, EventArgs e)
        {
            ResetGui();
        }

        private void ResetGui()
        {
            txt_HoTen.Text = String.Empty;
            txt_DiaChi.Text = String.Empty;
            txt_DienThoai.Text = String.Empty;
            txt_Email.Text = String.Empty;
        }

        private void KhachHangGUI_Load(object sender, EventArgs e)
        {
            ResetGui();
        }

        private void txt_DienThoai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar) &&
                e.KeyChar != '+')
                e.Handled = true;
            if (e.KeyChar == '+' &&
                (sender as TextBox).Text.IndexOf('+') > -1)
                e.Handled = true;
        }
    }
}
